﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Xml;

namespace Hisun.View.Webservice
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
         
    public class WebService1 : System.Web.Services.WebService
    {
        SqlConnection sqlCon;
        //string strCon = "Data Source=ABC-RB\\SQLEXPRESS;Initial Catalog=hisuntest;Integrated Security=True";
        string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["hisunConnectionString"].ConnectionString;

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]
        public string Testconnect()
        {
            try
            {

                sqlCon = new SqlConnection(strCon);

                sqlCon.Open();

                string re = "连接成功";

                return re;
            }

            catch
            {


                return "连接失败";

            }
        }
        [WebMethod]
        public XmlDocument getABC_workcenter(string aid, string cid) //
        {

            string strQuery1 = @"select  '" + aid + "' as 账套ID, '" + cid + "' as 公司ID,作业中心ID,作业中心名称,作业中心描述,类型,是否直接成本 from TABC_JS_CostCenter where 停用='0' and ( 类型='BG' or 类型='BF') order by 作业中心ID";


            sqlCon = new SqlConnection(strCon);
            sqlCon.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(strQuery1, sqlCon);

            DataSet ds = new DataSet();
            dataAdapter.Fill(ds, "table0");

            System.Xml.XmlDataDocument _XmlDataDocument = new System.Xml.XmlDataDocument(ds);
            return _XmlDataDocument;

        }
        [WebMethod]
        public XmlDocument getABC_costwcenter(string aid, string cid)
        {
            //        string strQuery1 = @"select TABC_JS_ProductInProcess.ID,TABC_JS_CostCenter.账套ID,TABC_JS_CostCenter.公司ID,TABC_JS_CostCenter.作业中心ID,TABC_JS_CostCenter.作业中心名称,TABC_JS_Product.产品账户ID,TABC_JS_Product.产品账户名称
            //                               from TABC_JS_Product, TABC_JS_ProductInProcess,TABC_JS_CostCenter 
            //                              where TABC_JS_CostCenter.作业中心ID=TABC_JS_ProductInProcess.作业中心ID and TABC_JS_ProductInProcess.产品ID=TABC_JS_Product.产品账户ID and (TABC_JS_CostCenter.类型='BF' or TABC_JS_CostCenter.类型='BG' or TABC_JS_CostCenter.类型='BZ')and (TABC_JS_ProductInProcess.可用='1') 
            //                                order by TABC_JS_ProductInProcess.ID";
            string strQuery1 = @"select TABC_JS_ProductInProcess.ID,'" + aid + "' as 账套ID,'" + cid + "' as 公司ID,TABC_JS_CostCenter.作业中心ID,TABC_JS_CostCenter.作业中心名称,TABC_JS_Product.产品账户ID,TABC_JS_Product.产品账户名称 from TABC_JS_Product, TABC_JS_ProductInProcess,TABC_JS_CostCenter where TABC_JS_CostCenter.作业中心ID=TABC_JS_ProductInProcess.作业中心ID and TABC_JS_ProductInProcess.产品ID=TABC_JS_Product.产品账户ID and (TABC_JS_CostCenter.类型='BF' or TABC_JS_CostCenter.类型='BG' or TABC_JS_CostCenter.类型='BZ')and (TABC_JS_ProductInProcess.可用='1') order by TABC_JS_ProductInProcess.ID";

            sqlCon = new SqlConnection(strCon);
            sqlCon.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(strQuery1, sqlCon);

            DataSet ds = new DataSet();
            dataAdapter.Fill(ds, "table0");
            System.Xml.XmlDataDocument _XmlDataDocument = new System.Xml.XmlDataDocument(ds);
            return _XmlDataDocument;
        }
        [WebMethod]
        public XmlDocument getABC_StockInCost(string aid, string cid)
        {
            string strQuery1 = @"select '" + aid + "' as 账套号,'" + cid + "' as 公司号,[存货编码],[存货名称],[会计期间],[数量],[单价],[金额],[billbid] from VABC_NC_StockInCostRe";
            sqlCon = new SqlConnection(strCon);
            sqlCon.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(strQuery1, sqlCon);

            DataSet ds = new DataSet();
            dataAdapter.Fill(ds, "table0");
            System.Xml.XmlDataDocument _XmlDataDocument = new System.Xml.XmlDataDocument(ds);
            return _XmlDataDocument;
        }
     
    }
}
